local P = 
{

}

P = NewClass(BaseTableObject, ClassFromFile(..., P))

function P:Init(prefabPath,parentObj,pos)
	self._time = 0
	self.prefabPath = prefabPath

	self.parentObj = parentObj
	self.obj = nil
	self.callback = nil

	self.lifeTime = nil

	self.pos = pos

	
	self:CreateEffectObject(prefabPath)
end

function P:CreateEffectObject(prefabPath)
	local callback = function(prefab, obj)
		if not prefab and not obj then
			logError("effect load effect failed:"..prefabPath)
			return
		end

		if not self.callback then
			ObjectPool.Recycle(obj)
			obj = nil
		end
		self.callback = nil


		self.obj = obj
		-- self.boneFollower = self.renderObj:GetComponent(typeof(Spine.Unity.BoneFollower))
		-- if self.boneName ~= "0" and self.boneName = "" then
		-- 	self.boneFollower.boneName = self.boneName
		-- 	self.boneFollower.followXYPosition = self.showInfo.boneFollower == 1
		-- 	self.boneFollower.followBoneRotation = self.showInfo.boneFollower == 1
		-- end

		self.obj.transform:SetParent(self.parentObj, false)
		self.obj.transform:SetPosition(self.pos.x, self.pos.y, self.pos.z)
		

		local go = self.obj
		local particleSystem = go:GetComponent(typeof(UnityEngine.ParticleSystem));
		if particleSystem then
			particleSystem:Play(true)
			--particleSystem:GetLoop()
			self.lifeTime = particleSystem:GetDuration()
		end

		local soundEffect = go:GetComponent(typeof(SoundEffect3d))
		if soundEffect then
			local priority = SoundEffectPriority.Skill
			-- if self.gameEntity.entity:isPlayer() then
			-- 	priority = SoundEffectPriority.SelfSkill
			-- elseif self.gameEntity.entity.className == "Avatar" then
			-- 	priority = SoundEffectPriority.PlayerSkill
			-- end
			soundEffect:Play(priority)
		end

	end
	self.callback = callback
	ObjectPool.LoadAssetAsync(prefabPath, callback);
end
function P:isHasBullet()
	return false
end
function P:FightUpdate(nDeltatime)
	if not self.isPaule then
		self._time = self._time + nDeltatime --*self.petGameObject.nSpeedPercent
	end
	local needDestroy = false
	if self.lifeTime and self.lifeTime <= self._time then
		needDestroy = true
	end 
	return needDestroy
end
function P:Pause()
	self.isPaule = true
	local particleSystem = self.obj:GetComponent(typeof(UnityEngine.ParticleSystem));
	if particleSystem then
		particleSystem:Pause(true)
	end
end
function P:Play()
	if not self.isPaule then
		return
	end
	self.isPaule = false
	local particleSystem = self.obj:GetComponent(typeof(UnityEngine.ParticleSystem));
	if particleSystem then
		particleSystem:Play(true)
	end
end

function P:End()

	if self.obj and not self.obj:Equals(nil) then
		local soundEffect = self.obj:GetComponent(typeof(SoundEffect3d))
		if soundEffect then
			soundEffect:Stop()
		end
		
		local particleSystem = self.obj:GetComponent(typeof(UnityEngine.ParticleSystem));
		if particleSystem then
			particleSystem:Stop(true)
		end
		ObjectPool.Recycle(self.obj)
	end
	
	if self.callback then
		ObjectPool.CancelAsyncLoad(self.prefabPath, self.callback)
		self.callback = nil
	end

	self.obj = nil
	self.callback = nil

	self.lifeTime = nil
	self.pos = nil



end
